package algorithm;

import java.util.Arrays;

public class leetcode_0621 {
    public int leastInterval(char[] tasks, int n) {

        int []count=new int[26];
        Arrays.fill(count,0);
        for(char c:tasks){
            count[c-'A']++;
        }
        int max=0;
        for(int num:count){
            max=Math.max(max,num);
        }

        int time=(max-1)*(n+1);
        for(int num:count){
            if(num==max){
                time++;
            }
        }
        return Math.max(time,tasks.length);

    }
}
